import collections
class Solution(object):
    def alertNames(self, keyName, keyTime):
        def convert(time):
            s = time.split(':')
            h = int(s[0])
            m = int(s[1])
            return h * 60 + m
        time = [convert(t) for t in keyTime]
        d = collections.defaultdict(list)
        for i in range(len(keyName)):
            d[keyName[i]].append(time[i])
        out = []
        for name in d:
            st = d[name]
            st.sort()
            n = len(st)
            index = 0
            while index + 2 < n:
                if st[index + 2] - st[index] <= 60:
                   out.append(name)
                   break
                else:
                    index += 1
        out.sort()
        return out

